//
//  TaskListCell.m
//  Qzone
//
//  Created by 王昭的Mac Air on 2018/6/12.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "TaskListCell.h"

@interface TaskListCell ()

@end

@implementation TaskListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configureUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.x = 10;
    frame.size.width = ScreenWidth - 2*10;
    [super setFrame:frame];
}

- (void)configureUI
{
    self.layer.cornerRadius = 10.0f;
    self.layer.masksToBounds = YES;
    
    [self.contentView addSubview:self.titleLbl];
    [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(self.mas_top).offset(10);
        make.height.equalTo(@(20));
    }];
    
    [self.contentView addSubview:self.statusBtn];
    [_statusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLbl.mas_bottom).offset(10);
        make.right.equalTo(self.mas_right).offset(-10);
        make.width.equalTo(@(85));
        make.height.equalTo(@(26));
    }];
    
    [self.contentView addSubview:self.diaView];
    [_diaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLbl.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        make.height.equalTo(@(20));
        make.width.equalTo(@(60));
    }];
    
    [self.contentView addSubview:self.golView];
    [_golView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.diaView.mas_right).offset(20);
        make.centerY.equalTo(self.diaView.mas_centerY);
        make.width.equalTo(self.diaView.mas_width);
        make.height.equalTo(self.diaView.mas_height);
    }];
    
    [self.contentView addSubview:self.expView];
    [_expView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.golView.mas_right).offset(20);
        make.centerY.equalTo(self.diaView.mas_centerY);
        make.width.equalTo(self.diaView.mas_width);
        make.height.equalTo(self.diaView.mas_height);
    }];
    
    [self.contentView addSubview:self.contentLbl];
    [_contentLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLbl.mas_left);
        make.right.equalTo(self.statusBtn.mas_left).offset(-10);
        make.top.equalTo(self.statusBtn.mas_top);
        make.bottom.equalTo(self.diaView.mas_top).offset(-10);
    }];
}

- (UILabel *)titleLbl
{
    if (!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        [_titleLbl attributeFont:FontFiftent
                       textColor:UIColorFromRGB(TextSizeOneColor)];
    }
    return _titleLbl;
}

- (UILabel *)contentLbl
{
    if (!_contentLbl) {
        _contentLbl = [[UILabel alloc] init];
        [_contentLbl attributeFont:FontThirteen
                         textColor:UIColorFromRGB(Text6Color)];
        _contentLbl.numberOfLines = 0;
    }
    return _contentLbl;
}

- (TaskLittleView *)diaView
{
    if (!_diaView) {
        _diaView = [[TaskLittleView alloc] init];
        _diaView.imgView.image = [UIImage imageNamed:@"icon_gold"];
        _diaView.titleLbl.text = @"100";
    }
    return _diaView;
}

- (TaskLittleView *)golView
{
    if (!_golView) {
        _golView = [[TaskLittleView alloc] init];
        _golView.imgView.image = [UIImage imageNamed:@"icon_diamond"];
        _golView.titleLbl.text = @"20";
    }
    return _golView;
}

- (TaskLittleView *)expView
{
    if (!_expView) {
        _expView = [[TaskLittleView alloc] init];
        _expView.imgView.image = [UIImage imageNamed:@"经验"];
        _expView.titleLbl.text = @"20";
    }
    return _expView;
}

- (UIButton *)statusBtn
{
    if (!_statusBtn) {
        _statusBtn = [[UIButton alloc] init];
        [_statusBtn attributeFont:FontFiftent
                        textColor:UIColorFromRGB(TextWhiteColor)
                           radius:3.0
                       background:UIColorFromRGB(BgTitleColor)];
        [_statusBtn setTitle:@"领取奖励" forState:0];
    }
    return _statusBtn;
}

+ (CGFloat)getCellHeightWithData:(NSDictionary *)dictionary
{
    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:convertToString(dictionary[@"content"])
                                                                  attributes:@{NSFontAttributeName:FontThirteen}];
    return [BaseUtil requireAttrHeightWithWidth:(ScreenWidth-5*10-85) attrText:attrStr]+10+20+10+10+10+20;
}

- (void)dataWithDictionary:(NSDictionary *)dictionary
{
    _titleLbl.text = convertToString(dictionary[@"title"]);
    _contentLbl.text = convertToString(dictionary[@"content"]);
    _diaView.titleLbl.text = convertToString(dictionary[@"dia"]);
    _golView.titleLbl.text = convertToString(dictionary[@"gol"]);
    _expView.titleLbl.text = convertToString(dictionary[@"exp"]);
}


@end
